package com.example.caoh.utils;

import java.util.HashMap;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;


/**
 * @author Ca(OH)2
 *
 * 2018年9月3日
 */
public class Result extends HashMap<String, Object> {
	/**
	 * 
	 */
	private static final long serialVersionUID = -4882485170023776586L;
	private static final int SUCCESS = 1;
	private static final int ERROR = -1;

	private Result() {
	}

	public Result success(String message, Object data) {
		this.put("code", SUCCESS);
		this.put("message", message);
		this.put("data", data);
		return this;
	}

	private Result success(String message, Object data, Integer total) {
		this.put("code", SUCCESS);
		this.put("message", message);
		this.put("data", data);
		this.put("total", total);
		return this;
	}
	private Result success(String message, Object data, Long total) {
		this.put("code", SUCCESS);
		this.put("message", message);
		this.put("data", data);
		this.put("total", total);
		return this;
	}

	public Result success(String message) {
		this.put("code", SUCCESS);
		this.put("message", message);
		return this;
	}
	
	public Result success(int code,String message) {
		this.put("code", code);
		this.put("message", message);
		return this;
	}
	public Result success() {
		this.put("code", SUCCESS);
		return this;
	}

	public Result error(String message) {
		this.put("code", ERROR);
		this.put("message", message);
		return this;
	}
	public Result error(int code,String message) {
		this.put("code", code);
		this.put("message", message);
		return this;
	}
	
	public static Result SUCCESS() {
		return new Result().success();
	}
	public static Result SUCCESS(String message, Object data) {
		return new Result().success(message, data);
	}
	
	public static Result SUCCESS(int code,String message) {
		return new Result().success(code, message);
	}

	public static Result SUCCESS(String message, Object datas, Integer total) {
		return new Result().success(message, datas, total);
	}
	public static Result SUCCESS(String message, Object datas, Long total) {
		return new Result().success(message, datas, total);
	}


	public static Result SUCCESS(String message) {
		return new Result().success(message);
	}

	public static Result ERROR(String message) {
		return new Result().error(message);
	}
	
	public static ResponseEntity<Object> ERROR(int code,HttpStatus status,String message) {
		return new ResponseEntity<Object>(new Result().error(code,message),status);
	}


}
